package com.juli.school.app.controller.module;

import java.util.List;
import java.util.Map;
import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.juli.school.dao.entity.Pub;
import com.juli.school.service.bo.ErBo;
import com.juli.school.service.bo.RecBo;
import com.juli.school.service.enums.EnumErType;
import com.juli.school.service.enums.EnumModule;
import com.juli.school.service.impl.ErService;
import com.juli.school.service.impl.RecService;
import com.juli.school.utils.core.model.CommonResp;
import com.juli.school.utils.core.model.ListResp;
import com.juli.school.utils.core.model.PageResp;

/**
 * 二手交易控制器
 * @author wjp
 * @date 2017年10月5日
 *
 */
@RequestMapping("er")
@Controller
public class ErController {

	@Resource
	private ErService erService;

	@Resource
	RecService recService;
	
	/**
	 * 添加一条二手交易
	 * @param love
	 * @return
	 */
	@RequestMapping(value = "add", method = RequestMethod.POST)
	@ResponseBody CommonResp<String> add(ErBo erBo) {
		return erService.add(erBo);
	}

	/**
	 * 修改一条二手交易
	 * @param love
	 * @return
	 */
	@RequestMapping(value = "erBo", method = RequestMethod.POST)
	@ResponseBody CommonResp<String> update(ErBo erBo) {
		return erService.update(erBo);
	}

	/**
	 * 删除一条二手交易记录
	 * @param snStamp
	 * @return
	 */
	@RequestMapping("delete")
	@ResponseBody CommonResp<String> delete(String snStamp,String stuId) {
		return erService.delete(snStamp,stuId);
	}
	
	@RequestMapping("listPage")
	@ResponseBody CommonResp<PageResp<Pub>> listPage(ErBo erBo) {
		return erService.listPage(erBo);
	}
	
	/**
	 * @Description: 增量查询信息列表
	 * @author gaoxiang
	 * @date 2017年9月16日 下午10:27:17
	 */
	@RequestMapping("/list")
	@ResponseBody CommonResp<ListResp<Pub>> list(ErBo req) {
		return erService.list(req);
	}
	
	@RequestMapping("detail")
	@ResponseBody CommonResp<ErBo> detail(ErBo erBo) {
		return erService.detail(erBo);
	}
	
	@RequestMapping("getErType")
	@ResponseBody CommonResp<Map<String,String>> getErType() {
		CommonResp<Map<String,String>> commonResp = new CommonResp<Map<String,String>>();
		commonResp.setData(EnumErType.list());
		return commonResp;
	}
	
	@RequestMapping("detailer")
	public String detailer(ErBo erBo,ModelMap model){
		model.put("type", EnumModule.Er);
		CommonResp<List<RecBo>> list = recService.list(erBo.getSnStamp());
		model.put("recs", list.getData());
		model.put("obj",  erService.detail(erBo));
		return "/detail/index";
	}
}
